package com.jboa.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.jboa.model.Function;
import com.jboa.model.Role;
import com.jboa.service.RoleService;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;


public class RoleAction extends ActionSupport{

	private Role role;
	private List<Role> rlist;
	private List<Integer> fids=new ArrayList<Integer>();
	private List<Function> functions;
	private RoleService roleService;

	
	public List<Integer> getFids() {
		return fids;
	}

	public void setFids(List<Integer> fids) {
		this.fids = fids;
	}

	public List<Function> getFunctions() {
		return functions;
	}

	public void setFunctions(List<Function> functions) {
		this.functions = functions;
	}

	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	public RoleService getRoleService() {
		return roleService;
	}

	public List<Role> getRlist() {
		return rlist;
	}

	public void setRlist(List<Role> rlist) {
		this.rlist = rlist;
	}

	public void setRoleService(RoleService roleService) {
		this.roleService = roleService;
	}
	
	public String operateRole(){
		rlist =roleService.operateRole();
		return SUCCESS;
	}
	// ����newRole����ķ���
	public String newRole() {
		roleService.newRole(role);
		return SUCCESS;
	}
	// ����findSingleRole����ķ���
	public String findSingleRole() {
		role = roleService.findSingleRole(role);
		return SUCCESS;
	}
	// ����modifyRole����ķ���
	public String modifyRole() {
		roleService.modifyRole(role);
		return Action.SUCCESS;
	}
	// ����removeRole����ķ���
	public String removeRole() {
		roleService.removeRole(role);
		return Action.SUCCESS;
	}
	// ����authorization����ķ���
	public String authorization() {
		//1����ȡ��ǰ��ɫ�����й���
		List <Integer>rids =roleService.hadRole(role);
		ServletActionContext.getRequest().setAttribute("had", rids);
		//2�����浱ǰ��ɫ��session
		role=roleService.findSingleRole(role);
		HttpSession hs = ServletActionContext.getRequest().getSession();
		hs.setAttribute("role", role);
		//3����ȡϵͳ�����й���
		functions = roleService.authorization(role);
		return Action.SUCCESS;
	}
	// ����changeRf����ķ���
	public String changeRf() {
		HttpSession hs = ServletActionContext.getRequest().getSession();
		roleService.changeRf(fids, (Role) hs.getAttribute("role"));
		return Action.SUCCESS;
	}
}
